<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="中文名称" prop="chineseName">
        <el-input
          v-model="queryParams.chineseName"
          placeholder="请输入中文名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:securityincidents:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:securityincidents:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:securityincidents:remove']"
        >删除</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['business:securityincidents:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="securityincidentsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="自增" align="center" prop="id" />
<!--      <el-table-column label="图片" align="center" prop="image" width="100">-->
<!--        <template slot-scope="scope">-->
<!--          <image-preview :src="previewUrl+'/'+scope.row.image" :width="50" :height="50"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="中文名称" align="center" prop="chineseName" show-overflow-tooltip />
      <el-table-column label="英文名称" align="center" prop="englishName"  show-overflow-tooltip />
      <el-table-column label="涉及国家" align="center" prop="differentCountries" show-overflow-tooltip  />
      <el-table-column label="结束时间" align="center" prop="endTime"  />
      <el-table-column label="事件属性" align="center" prop="eventProperties" show-overflow-tooltip  />
      <el-table-column label="事件相关关键词" align="center" prop="eventSubjectKeywords" show-overflow-tooltip />
      <el-table-column label="事件影响" align="center" prop="eventImpact" show-overflow-tooltip  />
      <el-table-column label="所属行业" align="center" prop="industryCategory" show-overflow-tooltip  />
      <el-table-column label="涉及IT系统" align="center" prop="itSystemsInvolved"  show-overflow-tooltip  />
      <el-table-column label="涉及工具(利用的漏洞)" align="center" prop="toolsAndVulnerabilitiesUsed" show-overflow-tooltip  />
<!--      <el-table-column label="事件过程" align="center" prop="incidentProcess" />-->
<!--      <el-table-column label="${comment}" align="center" prop="allInfo" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:securityincidents:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:securityincidents:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改安全事件对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="中文名称" prop="chineseName">
          <el-input v-model="form.chineseName" placeholder="请输入中文名称" />
        </el-form-item>
        <el-form-item label="英文名称" prop="englishName">
          <el-input v-model="form.englishName" placeholder="请输入英文名称" />
        </el-form-item>
        <el-form-item label="涉及国家" prop="differentCountries">
          <el-input v-model="form.differentCountries" placeholder="请输入涉及国家" />
        </el-form-item>

        <el-form-item label="结束时间" prop="pubDate">
          <el-date-picker clearable
                          v-model="form.endTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="事件属性" prop="eventProperties">
          <el-input v-model="form.eventProperties"  type="textarea" placeholder="请输入事件属性" />
        </el-form-item>
        <el-form-item label="事件相关关键词" prop="eventSubjectKeywords">
          <el-input v-model="form.eventSubjectKeywords"  type="textarea"  placeholder="请输入事件相关关键词" />
        </el-form-item>
        <el-form-item label="事件影响" prop="eventImpact">
          <el-input v-model="form.eventImpact" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="所属行业" prop="industryCategory">
          <el-input v-model="form.industryCategory" type="textarea" placeholder="请输入所属行业" />
        </el-form-item>
        <el-form-item label="涉及IT系统" prop="itSystemsInvolved">
          <el-input v-model="form.itSystemsInvolved"  type="textarea" placeholder="请输入涉及IT系统" />
        </el-form-item>
        <el-form-item label="涉及工具(利用的漏洞)" prop="toolsAndVulnerabilitiesUsed">
          <el-input v-model="form.toolsAndVulnerabilitiesUsed" type="textarea" placeholder="请输入涉及工具(利用的漏洞)" />
        </el-form-item>
        <el-form-item label="事件过程" prop="incidentProcess">
          <el-input v-model="form.incidentProcess" type="textarea" placeholder="请输入内容" />
        </el-form-item>
<!--        <el-form-item label="${comment}" prop="allInfo">-->
<!--          <el-input v-model="form.allInfo" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->



<!--        <el-form-item label="原文件" prop="fjFile">-->
<!--          <file-upload v-model="form.fjFile"  :limit="1"/>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="译文文件" prop="ywFile">-->
<!--          <file-upload v-model="form.ywFile"  :limit="1"/>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="精翻文件" prop="jfFile">-->
<!--          <file-upload v-model="form.jfFile"  :limit="1"/>-->
<!--        </el-form-item>-->

      </el-form>
      <el-form ref="formfj" label-width="120px">
        <el-form-item label="图片" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'image'"
              :biz-type="'download'"
              :limit="1"
              style="margin-left: 20px"
              table-type="1"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>
      <el-form ref="formfj" label-width="120px">
        <el-form-item label="原文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz001'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="1"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>

      <el-form ref="formfj" label-width="120px">
        <el-form-item label="译文文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz002'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="1"
            ></FileUpload>
          </div>
        </el-form-item>

      </el-form>
        <el-form ref="formfj" label-width="120px">
          <el-form-item label="精翻文件" prop="ysSm">
            <div>
              <FileUpload
                v-if="open"
                ref="expertRef"
                :disabled="true"
                :businessId="form.id"
                :business-type="'bz003'"
                :biz-type="'download'"
                :limit="1"
                :file-size="200"
                :file-type="['pdf']"
                style="margin-left: 20px"
                table-type="1"
              ></FileUpload>
            </div>
          </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listSecurityincidents, getSecurityincidents, delSecurityincidents, addSecurityincidents, updateSecurityincidents } from "@/api/business/securityincidents";
import Pictures from '@/components/Pictures'
import FileUpload from '@/components/fileUpload_neww.vue'
import {  saveUpdateFile  } from "@/api/business/file";

import { guid } from '@/utils/utils'
export default {
  name: "Securityincidents",
  components: { Pictures,FileUpload },
  props: {
    tableId: {
      type: String,
    }
  },
  data() {
    return {
      previewUrl: process.env.VUE_APP_API_BASE_URL,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 安全事件表格数据
      securityincidentsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tableId: null,
        chineseName: null,
        englishName: null,
        differentCountries: null,
        endTime: null,
        eventProperties: null,
        eventSubjectKeywords: null,
        eventImpact: null,
        industryCategory: null,
        itSystemsInvolved: null,
        toolsAndVulnerabilitiesUsed: null,
        incidentProcess: null,
        allInfo: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      selectImageOpen: false,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    selectJlProduct(row) {
      this.form.image = row.s3Url
      console.log(row.s3Url)
      this.selectImageOpen = false
      console.log(this.form)
      this.saveFj('image',this.form.id,this.form.image)
    },
    saveFj(businessType,businessId,url){
      var  param={
        businessType:businessType,
        businessId:businessId,
        url:url
      }
      saveUpdateFile(param).then(res => {
        this.$modal.msgSuccess("上传成功");
      })
    },
    selectImage() {
      this.title = '选择图片'
      this.selectImageOpen = true
    },
    cancelQuJldialog(){
      this.selectImageOpen = false
    },
    /** 查询安全事件列表 */
    getList() {
      this.loading = true;

      listSecurityincidents(this.queryParams).then(response => {
        this.securityincidentsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        tableId: null,
        chineseName: null,
        englishName: null,
        differentCountries: null,
        createTime: null,
        endTime: null,
        eventProperties: null,
        eventSubjectKeywords: null,
        eventImpact: null,
        industryCategory: null,
        itSystemsInvolved: null,
        toolsAndVulnerabilitiesUsed: null,
        incidentProcess: null,
        allInfo: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加安全事件";
      let mizId = guid().replace(/-/g, '');
      this.form.id = mizId
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSecurityincidents(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改安全事件";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSecurityincidents(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSecurityincidents(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除安全事件编号为"' + ids + '"的数据项？').then(function() {
        return delSecurityincidents(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/securityincidents/export', {
        ...this.queryParams
      }, `securityincidents_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
